var koa = require("koa");
var Router = require("koa-router")

var app = new koa();
var router = new Router();

// app.use(async (ctx)=>{
//     ctx.body = "这是一个中间件"
// })

// app.use(async (ctx, next)=>{
//     console.log(new Date());
//     await next()
// })


router.get('/', async (ctx) => {
    ctx.body = "this is index";
})
router.get('/news', async (ctx, next) => {
    console.log('这是新闻')
    await next()
})
router.get('/news', async (ctx) => {
    ctx.body = "新闻列表";
})
router.get('/newsContent/:id/:aid', async (ctx) => {
    ctx.body = "新闻详情";
})


app.use(async (ctx, next)=> {
    console.log("无路如何都打印");
    await next();
    if(ctx.status == 404){
        ctx.status = 404;
        ctx.body = "404"
    }else{
        console.log(ctx.url)
    }
})


app.use(router.routes());
app.use(router.allowedMethods);


app.listen(3000);


